
function draging(divId){
    $(document).ready(function () {
            $("#"+divId).mousedown(function (e) { //e鼠标事件  
                $(this).css("cursor", "move"); //改变鼠标指针的形状  
                var offset = $(this).offset(); //DIV在页面的位置  
                var x = e.pageX - offset.left; //获得鼠标指针离DIV元素左边界的距离  
                var y = e.pageY - offset.top; //获得鼠标指针离DIV元素上边界的距离  
                $(document).bind("mousemove", function (ev) { //绑定鼠标的移动事件，因为光标在DIV元素外面也要有效果，所以要用doucment的事件，而不用DIV元素的事件  
                  $("#"+divId).stop(); //加上这个之后  
                    var _x = ev.pageX - x; //获得X轴方向移动的值  
                    var _y = ev.pageY - y; //获得Y轴方向移动的值  
                  $("#"+divId).animate({ left: _x + "px", top: _y + "px" }, 0);
                });
            });
            $(document).mouseup(function () {
               $("#"+divId).css("cursor", "default");
                $(this).unbind("mousemove");
            });
        });  
}

function moveObj(obj) {
    obj.style.cursor = "move";
    obj.onmousedown = function (e) {
        obj.style.position = "absolute";
        var top = obj.offsetTop;
        var left = obj.offsetLeft;
        var drag_x = document.all ? event.clientX : e.pageX;
        var drag_y = document.all ? event.clientY : e.pageY;

        var clientwidth = obj.clientWidth;
        var clientheight = obj.clientHeight;

        if (drag_x <= 26 + left && drag_y <= clientheight + top) {
            var selection = disableSelection(document.body);
            var move = function (e) {
                obj.style.left = left + (document.all ? event.clientX : e.pageX) - drag_x + "px";
                obj.style.top = top + (document.all ? event.clientY : e.pageY) - drag_y + "px";
            };
            var stop = function (e) {
                removeEvent(document, "mousemove", move);
                removeEvent(document, "mouseup", stop);
                if (selection) {
                    selection();
                    delete selection;
                }
            };
            addEvent(document, "mousemove", move);
            addEvent(document, "mouseup", stop);
            selection();
        }
    }
};


function moveObjByVH(obj, vh, cursorDefault) {
    if (!cursorDefault) {
        obj.style.cursor = "move";
    }
    obj.onmousedown = function (e) {
        obj.style.position = "absolute";
        var top = obj.offsetTop;
        var left = obj.offsetLeft;
        var drag_x = document.all ? event.clientX : e.pageX;
        var drag_y = document.all ? event.clientY : e.pageY;

        var clientwidth = obj.clientWidth;
        var clientheight = obj.clientHeight;

        if (vh == "v") {
            if (drag_x <= clientwidth + left && drag_y <= 26 + top) {
                var selection = disableSelection(document.body);
                var move = function (e) {
                    obj.style.left = left + (document.all ? event.clientX : e.pageX) - drag_x + "px";
                    obj.style.top = top + (document.all ? event.clientY : e.pageY) - drag_y + "px";
                };
                var stop = function (e) {
                    removeEvent(document, "mousemove", move);
                    removeEvent(document, "mouseup", stop);
                    if (selection) {
                        selection();
                        delete selection;
                    }
                };

                addEvent(document, "mousemove", move);
                addEvent(document, "mouseup", stop);
                selection();
            }
        }
        else {
            if (drag_x <= 26 + left && drag_y <= clientheight + top) {
                var selection = disableSelection(document.body);
                var move = function (e) {
                    obj.style.left = left + (document.all ? event.clientX : e.pageX) - drag_x + "px";
                    obj.style.top = top + (document.all ? event.clientY : e.pageY) - drag_y + "px";
                };
                var stop = function (e) {
                    removeEvent(document, "mousemove", move);
                    removeEvent(document, "mouseup", stop);
                    if (selection) {
                        selection();
                        delete selection;
                    }
                };


                addEvent(document, "mousemove", move);
                addEvent(document, "mouseup", stop);
                selection();
            }
        }
    }
};

function addEvent(target, type, listener, capture) { return eventHandler(target, type, listener, true, capture); };

function removeEvent(target, type, listener, capture) { return eventHandler(target, type, listener, false, capture); };

function eventHandler(target, type, listener, add, capture) {
    type = type.substring(0, 2) === "on" ? type.substring(2) : type;
    if (document.all) {
        add ? target.attachEvent("on" + type, listener) : target.detachEvent("on" + type, listener);
    } else {
        capture = (typeof capture === "undefined" ? true : (capture === "false" ? false : ((capture === "true") ? true : (capture ? true : false))));
        add ? target.addEventListener(type, listener, capture) : target.removeEventListener(type, listener, capture);
    }
};

function disableSelection(target) {
    var disable = true;
    var oCursor = document.all ? target.currentStyle["cursor"] : window.getComputedStyle(target, null).getPropertyValue("cursor");
    var returnFalse = function (e) {
        e.stopPropagation();
        e.preventDefault();
        return false;
    };
    var returnFalseIE = function () { return false; };
    var selection = function () {
        if (document.all) {
            disable ? addEvent(target, "selectstart", returnFalseIE) : removeEvent(target, "selectstart", returnFalseIE);
        } else {
            disable ? addEvent(target, "mousedown", returnFalse, false) : removeEvent(target, "mousedown", returnFalse, false);
        }
        target.style.cursor = disable ? "default" : oCursor;
        disable = !disable;
    };
    return selection;
};
